package com.zzzyh.forumsystemclient.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 郑雨杭
 * @create 2025/5/27 - 15:38
 * 统一接口返回格式
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppResult <T>{
    private Integer code;
    private String message;
    private T data;

    public AppResult(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    //各种成功
    public static <T> AppResult<T> success() {
        AppResult<T> result = new AppResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        return result;
    }
    public static <T> AppResult<T> success(String message) {
        AppResult<T> result = new AppResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(message);
        return result;
    }

    public static <T> AppResult<T> success(T data) {
        AppResult<T> result = new AppResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(ResultCode.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> AppResult<T> success(String message, T data) {
        AppResult<T> result = new AppResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> AppResult<T> success(ResultCode resultCode) {
        AppResult<T> result = new AppResult<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }

    //各种失败

    public static <T> AppResult<T> failed() {
        AppResult<T> result = new AppResult<>();
        result.setCode(ResultCode.FAILED.getCode());
        result.setMessage(ResultCode.FAILED.getMessage());
        return result;
    }

    public static <T> AppResult<T> failed(String message) {
        AppResult<T> result = new AppResult<>();
        result.setCode(ResultCode.FAILED.getCode());
        result.setMessage(message);
        return result;
    }

    public static <T> AppResult<T> failed(ResultCode resultCode) {
        AppResult<T> result = new AppResult<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }
}
